﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DesignPatterns.FacadePattern
{
    public class Mortgage
    {
        private Bank bank = new Bank();

        private Loans loan = new Loans();

        private Credit credit = new Credit();
        
        public bool IsEligible(BankCustomer cust, int amount)
        {
            Console.WriteLine("{0} applies for {1:C} loan\n", cust.Name, amount);
            
            bool eligible = true;
            
            // Check creditworthyness of applicant
            if (!bank.HasSufficientSavings(cust, amount))
            {
                eligible = false;
            }
            else if (!loan.HasNoBadLoans(cust))
            {
                eligible = false;
            }
            else if (!credit.HasGoodCredit(cust))
            {
                eligible = false;
            }
            
            return eligible;
        }
    }
}
